package Exercise;

import java.util.Arrays;

class Card implements Comparable<Card> {
    public int val;
    public String suit;

    public Card(int val, String suit) {
        this.val = val;
        this.suit = suit;
    }
    private static final String suits="♠♣♦♥";
    @Override
    public int compareTo(Card o) {
        int result=this.val - o.val;
        if(result==0) {
            return suits.indexOf(this.suit)-suits.indexOf(o.suit);
        }
        return result;
    }

    @Override
    public String toString() {
        return "("+val+","+suit+")";
    }
}

public class Test {

    public static void main(String[] args) {
        //对自定义类型数组排序
        Card[] cards={
                new Card(10,"♦"),
                new Card(1,"♥"),
                new Card(6,"♦"),
                new Card(6,"♠"),
                new Card(2,"♥"),
                new Card(2,"♣"),
        };
        Arrays.sort(cards);
        System.out.println(Arrays.toString(cards));
    }

    public static void main1(String[] args) {
        //对基本类型数组排序
        int[] arrInt={1,9,4,3,2};
        Arrays.sort(arrInt);
        for(int i:arrInt) {
            System.out.print(i+" ");
        }
        System.out.println();

        double[] arrDouble={2.3,2.1,3.0,1.0,1.02};
        Arrays.sort(arrDouble);
        for(double d:arrDouble) {
            System.out.print(d+" ");
        }

        System.out.println();

        char[] arrChar={'h','c','z','b','a'};
        Arrays.sort(arrChar);
        for(char c:arrChar) {
            System.out.print(c+" ");
        }
    }


    public static void main2(String[] args) {
        float f = 123456789f;
        System.out.println(f);
        double d = 123456789;
        System.out.println(d);
    }
}
